#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 500010;
typedef pair<int, int> PII; // aim, idx
int n, m, s;
int e[N], h[N], ne[N], idx;
vector<PII> v[N];
int st[N], p[N];
int ans[N]; // 记录每次询问的结果
int depth[N];
PII q[N]; // 存询问
int Find(int x)
{
	if(p[x] != x) p[x] = Find(p[x]);
	return p[x];
}
void Add(int a, int b)
{
	e[idx] = b;
	ne[idx] = h[a];
	h[a] = idx ++;
}
void dfs(int x)
{
	st[x] = true;
	for(int i = h[x]; i != -1; i = ne[i])
	{
		int j = e[i];
		if(!st[j])
		{
			dfs(j);
			p[j] = x;
		}
	}
	for(int i = 0; i < v[x].size(); i++)
	{
		int val = v[x][i].first, id = v[x][i].second;
		if(st[val]) ans[id] = Find(val);
	}
}
int st2[N];
void dfs2(int x, int cnt)
{
	st2[x] = true;
	for(int i = h[x]; i != -1; i = ne[i])
	{
		int j = e[i];
		cout << "j: --" << j << endl;
		if(!st2[j])
		{
			depth[j] = cnt;
			cout << "--j" << j << ":" << cnt << endl;
			dfs2(j, cnt + 1);
		}
	}
}
int main()
{
	cin >> n >> m >> s;
	memset(h, -1, sizeof h);
	for(int i = 1; i <= n; i++) p[i] = i;
	for(int i = 0; i < n - 1; i++)
	{
		int x, y;
		cin >> x >> y;
		Add(x, y), Add(y, x);
	}
	depth[1] = 1;
	dfs2(1, 2); // 
	for(int i = 1; i <= n; i ++)
	{
		cout << "i: " << i << ":"<< depth[i] << endl;
	}
	int prev = 1;
	for(int i = 0; i < m; i++)
	{
		int idx;
		cin >> idx;
		v[idx].push_back({prev, i});
		v[prev].push_back({idx, i});
		q[i] = {idx, prev};
		prev = idx;
	}
	dfs(s);
	// for(int i = 0; i < m; i++) cout << ans[i] << " ";
	// ans 中存的就是每次询问的最近公共祖先
	int cnt = 0;
	for(int i = 0; i < m; i++)
	{
		int x1 = depth[q[i].first], x2 = depth[q[i].second];
		int mod = depth[ans[i]];
		cnt += (x1 + x2 - 2 * mod);
	}
	cout << cnt;
}